﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using NUnit.Framework;
using Smith.BuildExtensions.ConfigurationTransformation;
using Assert = NUnit.Framework.Assert;

namespace BuildExtensionsTests
{
    [TestClass]
    public class KeyReaderTest
    {
        [TestMethod]
        public void GetKeysShouldReturnEmtyListIfNoKeysAreAvailable()
        {
            KeyReader reader = new KeyReader();
            ICollection<string> keys = reader.GetKeys("contents");

            Assert.That(keys.Count, Is.EqualTo(0));
        }

        [TestMethod]
        public void GetKeysShouldReturnEmtyListIfContentsIsEmpty()
        {
            KeyReader reader = new KeyReader();
            ICollection<string> keys = reader.GetKeys(string.Empty);

            Assert.That(keys.Count, Is.EqualTo(0));
        }

        [TestMethod]
        public void GetKeysShouldThrowArgumentNullExceptionIfContentsIsNull()
        {
            KeyReader reader = new KeyReader();
            Assert.Throws<ArgumentNullException>(() => reader.GetKeys(null));
        }

        [TestMethod]
        public void GetKeysShouldReturnAllKeys()
        {
            KeyReader reader = new KeyReader();
            ICollection<string> keys = reader.GetKeys("$(Username) $(Password) $(CodeName) <!--$(HostName)--> <![CDATA[$(Deployment)]]>");

            Assert.That(keys.Count, Is.EqualTo(5));
            Assert.That(keys.Contains("Username"), Is.True);
            Assert.That(keys.Contains("Password"), Is.True);
            Assert.That(keys.Contains("CodeName"), Is.True);
            Assert.That(keys.Contains("HostName"), Is.True);
            Assert.That(keys.Contains("Deployment"), Is.True);
        }
    }
}
